package top.lywivan.reggie.util;

import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.dysmsapi.model.v20170525.SendSmsRequest;
import com.aliyuncs.dysmsapi.model.v20170525.SendSmsResponse;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.profile.DefaultProfile;

/**
 * 短信发送工具类
 */
public class SMSUtils {

	public static void sendMessage(String phoneNumbers,String param){

		DefaultProfile profile = DefaultProfile.getProfile("cn-hangzhou", "LTAI5t9d6ZFeKq6d56UWnvU3", "JMNItvcvGpydwC57wfN4pIUlqkUY9D");
		IAcsClient client = new DefaultAcsClient(profile);

		SendSmsRequest request = new SendSmsRequest();
		request.setSysRegionId("cn-hangzhou");
		//给谁发的
		request.setPhoneNumbers(phoneNumbers);
		//签名
		request.setSignName("黑马健康");
		//模板
		request.setTemplateCode("SMS_171111537");

		request.setTemplateParam("{\"code\":\""+param+"\"}");
		try {
			SendSmsResponse response = client.getAcsResponse(request);

			System.out.println(response.getMessage());
		}catch (ClientException e) {
			e.printStackTrace();
		}
	}

}
